function [U_Gumbel, V_Gumbel, Phi_Gumbel, D_Gumbel,Mmaritalprem_Gumbel,Wmaritalprem_Gumbel]=...
         param_Gumbel_closedform(PYX_cond, PXY_cond, ntypes_m, ntypes_w)
%% U,V
U_Gumbel=zeros(ntypes_m,ntypes_w);
for i=1:ntypes_m
for j=1:ntypes_w
    U_Gumbel(i,j)=log(PYX_cond(i,j)/PYX_cond(i,end));  
end
end

V_Gumbel=zeros(ntypes_m,ntypes_w);
for j=1:ntypes_w
for i=1:ntypes_m
    V_Gumbel(i,j)=log(PXY_cond(j,i)/PXY_cond(j,end)); 
end
end



%% Phi
Phi_Gumbel=zeros(ntypes_m,ntypes_m); %here ntypes_m=ntypes_w
for i=1:ntypes_m
    for j=1:ntypes_m
        Phi_Gumbel(i,j)=U_Gumbel(i,j)+V_Gumbel(i,j); 
    end
end

%% D
D_Gumbel=zeros(ntypes_m,ntypes_m); %here ntypes_m=ntypes_w
for i=1:ntypes_m-1
    for k=i+1:ntypes_m
        D_Gumbel(i,k)=Phi_Gumbel(i,i)+Phi_Gumbel(k,k)-Phi_Gumbel(i,k)-Phi_Gumbel(k,i); 
    end
end

%% Marital college premium 
Mmaritalprem_Gumbel(1)=log(exp(U_Gumbel(1,1))+exp(U_Gumbel(1,2))+exp(U_Gumbel(1,3))+exp(U_Gumbel(1,4))+1)+ 0.5772; %conditional on X=1
Mmaritalprem_Gumbel(2)=log(exp(U_Gumbel(2,1))+exp(U_Gumbel(2,2))+exp(U_Gumbel(2,3))+exp(U_Gumbel(2,4))+1)+ 0.5772; %conditional on X=2
Mmaritalprem_Gumbel(3)=log(exp(U_Gumbel(3,1))+exp(U_Gumbel(3,2))+exp(U_Gumbel(3,3))+exp(U_Gumbel(3,4))+1)+ 0.5772; %conditional on X=3
Mmaritalprem_Gumbel(4)=log(exp(U_Gumbel(4,1))+exp(U_Gumbel(4,2))+exp(U_Gumbel(4,3))+exp(U_Gumbel(4,4))+1)+ 0.5772; %conditional on X=4


Wmaritalprem_Gumbel(1)=log(exp(V_Gumbel(1,1))+exp(V_Gumbel(2,1))+exp(V_Gumbel(3,1))+exp(V_Gumbel(4,1))+1)+ 0.5772; %conditional on Y=1
Wmaritalprem_Gumbel(2)=log(exp(V_Gumbel(1,2))+exp(V_Gumbel(2,2))+exp(V_Gumbel(3,2))+exp(V_Gumbel(4,2))+1)+ 0.5772; %conditional on Y=2
Wmaritalprem_Gumbel(3)=log(exp(V_Gumbel(1,3))+exp(V_Gumbel(2,3))+exp(V_Gumbel(3,3))+exp(V_Gumbel(4,3))+1)+ 0.5772; %conditional on Y=3
Wmaritalprem_Gumbel(4)=log(exp(V_Gumbel(1,4))+exp(V_Gumbel(2,4))+exp(V_Gumbel(3,4))+exp(V_Gumbel(4,4))+1)+ 0.5772; %conditional on Y=4



end

